<template>
  <div class="main">
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <span><template>
          <!-- <el-radio-group v-model="radio">
            <el-radio v-for="item in myProject" :key="item.projectId" :label="item.projectId" @change="showradio">{{
              item.projectName }}</el-radio>
          </el-radio-group> -->
        </template></span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="Close">取 消</el-button>

        <download-excel class="btn btn-default" :data="json_data" :fields="json_fields" :type="type" name="工作日志.xlsx" worksheet='测试一下'
          :before-finish="myclick">
          <el-button type="primary">确 定</el-button>
        </download-excel>
 <!-- <download-excel class="btn btn-default"
  :data="dataForExcel">
          <el-button type="primary">确 定</el-button>
        </download-excel> -->

      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getMyProjectAll, getStatExport,getMyProjectById } from "@/api/system/project";
import {
  getIndexProjectStat,
  getIndexFillInfo,
  getIndexLoginUser
} from "@/api/dashboard";
export default {
  data() {
    return {
      dialogVisible: false,
      status: null,
      radio: null,
      localDate: "",
      type: "xlsx",
      myProject: [],
      json_fields: {
        //生成excel的字段：导出数据的字段
        人员姓名: "nickName",
        项目名称: "projectName",
        工作时长:'useHour',
         工作内容: "daily",
      },
      json_data: [],
      nickName:'',
      // dataForExcel: [
      //     { colA: "Hello", colB: "World" },
      //     {
      //       colA: "Multi-line",
      //       /* Multi-line value: */
      //       colB:
      //         "This is a long paragraph\nwith multiple lines\nthat should show in a single cell.",
      //     },
      //     { colA: "Another", colB: "Regular cell" },
      //   ],
    };
  },
  methods: {
    open() {
      // 根据用户id获取用户参加的项目
      getMyProjectById({userId:129}).then(res => {
        if (res.code == 200) {
          this.myProject = res.data;
          this.dialogVisible = true;
        }
      });
      console.log(this.myProject,this.nickName);
      this.myProject.forEach(el=> {
        console.log(el);
        this.json_fields[el.date]=el.date
        // if (el.projectHours) {
        //   el.projectHours.forEach(fl => {
        //     this.json_data.push({
        //       date:el.date,
        //       nickName:this.nickName,
        //       projectName:fl.projectName,
        //       useHour:fl.useHour,
        //       daily:fl.daily,
        //       postName:el.postName,
        //       totalHour:el.totalHour
        //     })
        //   });
        // }else{
          this.json_data.push({
              nickName:this.nickName,
              projectName:'暂无内容',
              useHour:'暂无内容',
              daily:'暂无内容',
          })
        // }
      });
      // this.json_data = this.myProject
      console.log(this.json_data);
    },
    Close() {
      this.radio = null;
      this.dialogVisible = false;
      if (this.status == 1) {
        this.$parent.defaultbtn = false;
        this.$parent.defaultbtntb = true;
      } else {
        this.$parent.defaultbtn = true;
        this.$parent.defaultbtntb = false;
      }
    },
    handleExport() {
      console.log(this.radio);
      let params = {};
      params.localDate = this.localDate;
      params.projectId = this.radio;
      getStatExport(params).then(res => {
        console.log(res);
        if (res.code == 200) {
          console.log(this.radio);
          res.data.fillInfos.forEach(el => {
            el.nickName = res.data.nickName;
            el.postName = res.data.postName;
            el.projectId = res.data.projectId;
            el.projectName = res.data.projectName;
            if (el.status == 1) {
              el.attendance = "已填报";
            }
            if (el.status == 2) {
              el.attendance = "未填报";
            }
            if (el.status == 3) {
              el.attendance = "无需填报";
            }
            if (el.status == 4) {
              el.attendance = "节假日";
            }
            if (el.status == 5) {
              el.attendance = "请假";
            }
            if (el.status == 6) {
              el.attendance = "调休";
            }
            if (el.useHour == null) {
              el.useHour = 0;
            }
          });
          this.json_data = res.data.fillInfos;
          console.log(this.json_data);
          //   this.radio = null;
          //   this.dialogVisible = false;
        }
      });
    },
    showradio(value) {
      console.log(value);
      console.log(this.radio);
      this.handleExport();
    },
    myclick(e) {
      
        console.log("我的事件",e);
      // this.radio = null;
      // this.dialogVisible = false;
      // if (this.status == 1) {
      //   this.$parent.defaultbtn = false;
      //   this.$parent.defaultbtntb = true;
      // } else {
      //   this.$parent.defaultbtn = true;
      //   this.$parent.defaultbtntb = false;
      // }
    },
    handleClose(done) {
      /*this.$confirm("确认关闭？")
        .then(_ => {
          this.Close();*/
      done();
      /*  })
        .catch(_ => {});*/
    }
  }
};
</script>

<style lang="scss" scoped>
.btn.btn-default {
  display: inline-block;
  margin-left: 8px;
}
</style>
